home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok59.lha
/
AmokEd_V1.02b
/
txt
/
EdMenu.mod
< prev
next >
Wrap
Text File
|
1993-08-15
|
8KB
|
371 lines
(*************************************************************************
:Program. EdMenu.mod
:Contents. Menu-Handline for Amok-Editor
:Author. Hartmut Goebel
:Copyright. Copyright © 1987 by Matthew Dillon
:Copyright. Oberon implementation Copyright © 1991 by Hartmut Goebel
:Language. Oberon
:Translator. Amiga Oberon Compiler V2.00
:History. V1.0, 25 Feb 1991 Hartmut Goebel [hG]
:History. V1.1, 24 Apr 1991 [hG] +memoryFail; Code opitmiert
:History. V1.1b 24 May 1991 [hG] optimiert wg. Oberon V2.00
:History. V1.1c 15 Oct 1991 [hG] ^AddItem (+Dummy-Loop)
:Date. 15 Oct 1991 14:41:20
*************************************************************************)
MODULE EdMenu;
IMPORT
e : Exec,
edE: EdErrors,
edG: EdGlobalVars,
edL: EdLowLevel,
g : Graphics,
I : Intuition,
lst: EdLists,
ol : OberonLib,
str: Strings,
sys: SYSTEM;
TYPE
XItemPtr = POINTER TO XItem;
XItem = STRUCT (item: I.MenuItem)
com: edG.StringPtr;
END;
VAR
Menu: I.MenuPtr;
MenuoffCnt: INTEGER;
DoMenuoffCnt: INTEGER;
doMenuDelReturn: BOOLEAN;
PROCEDURE MenuStrip*(win: I.WindowPtr);
BEGIN
IF (MenuoffCnt=0) AND (Menu#NIL) AND I.SetMenuStrip(win,Menu^) THEN
e.Forbid();
EXCL(win.flags,I.rmbTrap);
e.Permit();
END;
END MenuStrip;
PROCEDURE Fixmenu;
VAR
menu: I.MenuPtr;
item: I.MenuItemPtr;
it: I.IntuiTextPtr;
row,col,maxc,scr: INTEGER;
BEGIN
col := 0;
menu := Menu;
WHILE menu#NIL DO
maxc := str.Length(menu.menuName^);
row := 0;
item := menu.firstItem;
WHILE item#NIL DO
it := item.itemFill;
item.topEdge := row;
scr := str.Length(it.iText^);
IF scr > maxc THEN maxc := scr END;
item.height := 10;
INC(row,item.height);
item := item.nextItem;
END;
maxc := (maxc * 8);
item := menu.firstItem;
WHILE item#NIL DO
item.width := maxc;
item := item.nextItem;
END;
menu.width := str.Length(menu.menuName^)*8+24;
menu.leftEdge := col;
menu.height := row;
INC(col,menu.width);
menu := menu.nextMenu;
END; (* WHILE menu#NIL *)
END Fixmenu;
PROCEDURE MenuOff;
VAR
txt: edG.TextHeaderPtr;
BEGIN
IF MenuoffCnt = 0 THEN
txt := edG.EditList.head(edG.TextHeader);
WHILE txt#NIL DO
I.ClearMenuStrip(txt.window);
e.Forbid();
INCL(txt.window.flags,I.rmbTrap);
e.Permit();
txt := txt.node.next(edG.TextHeader);
END;
END;
INC(MenuoffCnt);
END MenuOff;
PROCEDURE MenuOn;
VAR
txt: edG.TextHeaderPtr;
BEGIN
IF (Menu#NIL) AND (MenuoffCnt=1) THEN
Fixmenu;
txt := edG.EditList.head(edG.TextHeader);
WHILE txt#NIL DO
IF I.SetMenuStrip(txt.window,Menu^) THEN
e.Forbid();
EXCL(txt.window.flags,I.rmbTrap);
e.Permit();
END;
txt := txt.node.next(edG.TextHeader);
END;
END;
DEC(MenuoffCnt);
END MenuOn;
PROCEDURE MenuToMacro*(string: edG.StringPtr): edG.StringPtr;
VAR
xitem: XItemPtr;
item: edG.StringPtr;
it: I.IntuiTextPtr;
menu: I.MenuPtr;
i: INTEGER;
BEGIN
i := 0;
WHILE (string[i]#0X) AND (string[i]#"-") DO
INC(i); END;
IF string[i] = "-" THEN
string[i] := 0X;
item := sys.ADR(string[i+1]);
menu := Menu;
WHILE menu # NIL DO
IF string^ = menu.menuName^ THEN
xitem := menu.firstItem(XItemPtr);
WHILE xitem # NIL DO
it := xitem.item.itemFill;
IF item^ = it.iText^ THEN
string[i] := "-";
RETURN xitem.com; END;
xitem := xitem.item.nextItem;
END;
END;
menu := menu.nextMenu;
END;
string[i] := "-";
END;
RETURN NIL;
END MenuToMacro;
PROCEDURE GetMenuCmd*(im: I.IntuiMessagePtr): edG.StringPtr;
VAR
item: XItemPtr;
BEGIN
item := I.ItemAddress(Menu^,im.code);
IF item # NIL THEN RETURN item.com;
ELSE RETURN NIL; END;
END GetMenuCmd;
(* gibt TRUE zurück, falls noch Items vorhanden sind *)
PROCEDURE DelItem(menu: I.MenuPtr; item: XItemPtr): BOOLEAN;
VAR
it: I.MenuItemPtr;
iptr: POINTER TO I.MenuItemPtr;
itxt: I.IntuiTextPtr;
BEGIN
iptr := sys.ADR(menu.firstItem); (* dahin gehört der Nachfolger *)
it := menu.firstItem;
WHILE it # NIL DO
IF item = it THEN
iptr^ := it.nextItem;
itxt := it.itemFill;
DISPOSE(itxt.iText);
DISPOSE(item.com);
DISPOSE(item); (* itxt hängt mit dran! SIZE(xitem)+SIZE(IntuitText) *)
IF menu.firstItem = NIL THEN RETURN FALSE;
ELSE RETURN TRUE; END;
END;
iptr := sys.ADR(it.nextItem);
it := iptr^;
END;
RETURN FALSE;
END DelItem;
(*-------------------------------------------------------------------------*)
(*
* menuclear
* menuadd header item command
* menudel header item
* menudelhdr header
*)
PROCEDURE doMenuOff*;
BEGIN
MenuOff;
INC(DoMenuoffCnt);
END doMenuOff;
PROCEDURE doMenuOn*;
BEGIN
IF DoMenuoffCnt#0 THEN
DEC(DoMenuoffCnt);
MenuOn;
END;
END doMenuOn;
PROCEDURE doMenuAdd*;
VAR
it: I.IntuiTextPtr;
menu: I.MenuPtr;
mpr: POINTER TO I.MenuPtr;
item: I.MenuItemPtr;
ipr: POINTER TO I.MenuItemPtr;
PROCEDURE NewName(xitem: XItemPtr); (* create new name *)
BEGIN
(*IF xitem.com # NIL THEN*) DISPOSE(xitem.com);(* END;*)
xitem.com := edL.CopyString(edG.Arg[2]);
MenuOn;
END NewName;
BEGIN
MenuOff;
LOOP (* Dummy *)
mpr := sys.ADR(Menu);
menu := Menu;
WHILE menu # NIL DO
IF edG.Arg[0]^ = menu.menuName^ THEN
ipr := sys.ADR(menu.firstItem);
item := ipr^;
WHILE item # NIL DO
it := item.itemFill;
IF edG.Arg[1]^ = it.iText^ THEN
NewName(item(XItem));
RETURN;
END;
ipr := sys.ADR(item.nextItem);
item := ipr^;
END;
EXIT;
END;
mpr := sys.ADR(menu.nextMenu);
menu := mpr^;
END;
(*
* Create new Menu
*)
ol.New(menu,sys.SIZE(I.Menu));
IF menu = NIL THEN
INCL(edG.Status,edG.memoryFail); edG.Rc := edE.cmdSevere;
RETURN;
END;
menu.nextMenu := mpr^;
mpr^ := menu;
menu.flags := {I.menuEnabled};
menu.menuName := sys.VAL(e.STRPTR,edL.CopyString(edG.Arg[0]));
ipr := sys.ADR(menu.firstItem);
ipr^ := NIL;
EXIT;
END; (* Dummy-Loop *)
(*
* Create New Item
*)
ol.New(item,sys.SIZE(XItem)+sys.SIZE(I.IntuiText));
IF item = NIL THEN
INCL(edG.Status,edG.memoryFail); edG.Rc := edE.cmdSevere;
RETURN;
END;
it := sys.VAL(e.ADDRESS,item)+sys.SIZE(XItem);
it.iText := edL.CopyString(edG.Arg[1]);
it.backPen := 1;
it.drawMode := g.jam2;
item.nextItem := ipr^; ipr^ := item; (* verketten *)
item.itemFill := it;
item.flags := {I.itemText,I.itemEnabled,I.highComp};
NewName(item(XItem));
END doMenuAdd;
PROCEDURE doMenuDelHdr*;
VAR
menu: I.MenuPtr;
mpr: POINTER TO I.MenuPtr;
BEGIN
MenuOff;
mpr := sys.ADR(Menu);
menu := mpr^;
WHILE menu # NIL DO
IF edG.Arg[0]^ = menu.menuName^ THEN
WHILE (menu.firstItem # NIL)
AND DelItem(menu,menu.firstItem(XItem)) DO
END;
mpr^ := menu.nextMenu;
DISPOSE(menu.menuName);
DISPOSE(menu);
MenuOn;
RETURN;
END; (* IF edG.Arg[0]^ = menu.menuName^ *)
mpr := sys.ADR(menu.nextMenu);
menu := mpr^;
END;
MenuOn;
END doMenuDelHdr;
PROCEDURE doMenuDel*;
VAR
menu: I.MenuPtr;
item: I.MenuItemPtr;
ipr: POINTER TO I.MenuItemPtr;
it: I.IntuiTextPtr;
xitem: XItemPtr;
BEGIN
MenuOff;
menu := Menu;
WHILE menu# NIL DO
IF edG.Arg[0]^ = menu.menuName^ THEN
ipr := sys.ADR(menu.firstItem); (* dahin gehört der Nachfolger *)
item := ipr^;
WHILE item # NIL DO
it := item.itemFill;
IF edG.Arg[1]^ = it.iText^ THEN
IF NOT DelItem(menu,item(XItem)) THEN
doMenuDelHdr; END;
MenuOn;
RETURN;
END;
ipr := sys.ADR(item.nextItem);
item := ipr^;
END;
END;
menu := menu.nextMenu;
END;
MenuOn;
END doMenuDel;
PROCEDURE doMenuClear*;
BEGIN
MenuOff;
WHILE Menu # NIL DO
edG.Arg[0] := sys.VAL(e.ADDRESS,Menu.menuName);
doMenuDelHdr;
END;
MenuOn;
END doMenuClear;
BEGIN
Menu := NIL; MenuoffCnt := 0; DoMenuoffCnt := 0;
CLOSE
(* MenuOff;
doMenuClear; *)
END EdMenu.